<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
if (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".inc.php",$_SERVER['PHP_SELF'])) {
	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";
	exit;
}



$box_content = new XTemplate ("skins/".$configSkin['value']."/styleTemplates/search.tpl");

// store search phrases to create cloud
if (isset($_GET['ps']) && $_GET['ps'] != NULL) {
	if ($_GET['sv'] == 1 && !isset($_GET['pageNum_product'])) {
	
		$getphraseresults = mysql_query("SELECT * FROM affiliSt_cloud ORDER BY searchPhrase ASC");
		$phraseresults = mysql_fetch_assoc($getphraseresults);
		
		$searchinsert =  ucwords(strtolower(strip_tags($_GET['ps'])));
		$searchinsert = str_replace($allCharacters, " ", $searchinsert);
		$searchinsert = str_replace(" ", "-", $searchinsert);
		
		do {
				
				if ($phraseresults['searchPhrase'] == $searchinsert) {
				$newsearchphrasecount = $phraseresults['searchPhraseCount'] + 1;
				mysql_query("UPDATE affiliSt_cloud SET searchPhraseCount = '$newsearchphrasecount' WHERE searchPhrase = '$searchinsert'");
				break;
				
				} else {
				$newsearchphrasecount = 1;
				}
			} while ($phraseresults = mysql_fetch_assoc($getphraseresults));
		
			if ($newsearchphrasecount == 1) {
			
			$sql = sprintf("INSERT INTO affiliSt_cloud (searchPhrase, searchPhraseCount) VALUES (%s, %s)",
					quote_smart($searchinsert),
					quote_smart($newsearchphrasecount));
			mysql_query($sql, $databaseConnect) or die(mysql_error());
			}
			
			

			// cookie for 5 recently searched products for userhistory.inc.php
			// php link
			$recentSearchLink = $installDir['value'].'index.php?case=search&ps='.str_replace(" ", "+", strip_tags($_GET['ps'])).'-:-'.$_GET['ps'];
			if (!isset($_COOKIE['recentlysearched'])) {
			setcookie("recentlysearched[0]", $recentSearchLink, time()+(60*60*24*365*10), "/", $_SERVER['SERVER_NAME']);
			} else {
				for ($vh=0;$vh<4;$vh++) {
					if (isset($_COOKIE['recentlysearched'][$vh]) && ($recentSearchLink != $_COOKIE['recentlysearched'][0] && $recentSearchLink != $_COOKIE['recentlysearched'][1] && $recentSearchLink != $_COOKIE['recentlysearched'][2] && $recentSearchLink != $_COOKIE['recentlysearched'][3] && $recentSearchLink != $_COOKIE['recentlysearched'][4])) {
					setcookie("recentlysearched[".($vh+1)."]", $_COOKIE['recentlysearched'][$vh], time()+(60*60*24*365*10), "/", $_SERVER['SERVER_NAME']);
					setcookie("recentlysearched[0]", $recentSearchLink, time()+(60*60*24*365*10), "/", $_SERVER['SERVER_NAME']);
					}
				}
			}
			
			
	}
}



$box_content->assign("DATA", "Search Products");

$box_content->assign("INSTALLDIR",$installDir['value']);
$box_content->assign("SKIN",$configSkin['value']);
$box_content->parse("search");
$box_content = $box_content->text("search");
?>